/*
 *  $Id: ResourceGroup.cs 1176 2010-11-08 11:19:45Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System.Collections.Generic;

namespace Ragima.Languages {
    /// <summary>
    /// Структура для набора пар идентификатор+ресурс, и так же языкового кода и префикса индентификаторов.
    /// Может создать по себе экземпляр локализатора.
    /// </summary>
    public struct ResourceGroup {
        public readonly string LangCode;
        public readonly string Prefix;
        public readonly ResourceItem[] Resources;

        public ResourceGroup(ResourceItem[] resources): this(string.Empty, string.Empty, resources) {}
        public ResourceGroup(string prefix, ResourceItem[] resources): this(string.Empty, prefix, resources) {}
        public ResourceGroup(string langCode, string prefix, ResourceItem[] resources) {
            LangCode = langCode;
            Prefix = prefix;
            Resources = resources;
        }

        public ILocalizer CreateLocalizer(string defaultLangCode) {
            return new ArrayLocalizer(string.IsNullOrEmpty(LangCode) ? defaultLangCode : LangCode, Prefix, Resources);
        }

        public static IEnumerable<ILocalizer> Create(string defaultLangCode, ResourceGroup[] groups) {
            foreach (var group in groups)
                yield return group.CreateLocalizer(defaultLangCode);
        }
    }
}
